package com.lw.carmanage.controller.advices;

import com.lw.carmanage.dto.R;
import com.lw.carmanage.exceptions.MyBaseException;
import com.lw.carmanage.exceptions.MyErrorCode;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author Administrator
 * @version 1.0
 * @description:
 * @date 2022/3/31 10:44
 */
@ControllerAdvice
@ResponseBody
public class MyBaseExceptionAdvice {

    @ExceptionHandler(MyBaseException.class)
    public static R processException(MyBaseException exception){
        System.err.println(exception.getMessage());
        return R.setError(exception.getCode(),exception.getMessage(),null);
    }

    @ExceptionHandler(Exception.class)
    public static R processException(Exception exception){
        System.err.println(exception.getMessage());
        return R.setError(MyErrorCode.FAIL,"网络异常，请检查网络",null);
    }
}
